﻿using System;
using Microsoft.Owin;
using Microsoft.Owin.Security.OAuth;
using Owin;
using SDCloudSolution.SDCloud.WebApi.Providers;

namespace SDCloudSolution.SDCloud.WebApi
{
    public partial class Startup
    {
        /// <summary>
        /// Configures the OAuth2 authorization protocol.
        /// </summary>
        /// <param name="app">The application.</param>
        public void ConfigureOAuth(IAppBuilder app)
        {
            var serverOptions = new OAuthAuthorizationServerOptions()
            {
                AllowInsecureHttp = true,
                TokenEndpointPath = new PathString("/account/token/v1"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = new AuthorizationServerProvider()
            };

            var bearerAuthenticationOptions = new OAuthBearerAuthenticationOptions();

            app.UseOAuthAuthorizationServer(serverOptions);
            app.UseOAuthBearerAuthentication(bearerAuthenticationOptions);
        }
    }
}